package com.game.majiang.vo;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import javax.sql.rowset.CachedRowSet;
import lombok.Data;
import lombok.extern.log4j.Log4j;
import net.sf.json.JSONArray;

import com.game.majiang.config.LogManager;
import com.game.majiang.logic.LogicServer;
import com.game.server.db.Parameter;
import com.game.server.db.ParameterType;
import com.game.server.db.SqlHelper;
import com.game.server.db.SqlHelperwrite;

import avatar.avatarparamdata;
import avatar.avatarparammanager;

@Log4j
@Data
public class AvatarparamVo {
	

	public static void initparam() {
		HashMap<String,String> map = new HashMap<String,String>();
		String sql = "select * from avatarparam";
		CachedRowSet rs = SqlHelper.getResultSet(sql);
		try {
			while (rs.next()) 
			{  
				avatarparamdata data = new avatarparamdata();
				data.id  = Integer.parseInt(rs.getString(1));
				data.difen  = Integer.parseInt(rs.getString(2));
				data.type  = Integer.parseInt(rs.getString(3));
				data.chaoguorennum  = Integer.parseInt(rs.getString(4));
				data.chaoguojiqirennum  = Integer.parseInt(rs.getString(5));
				data.robotcount  = Integer.parseInt(rs.getString(6));
				data.bili1 = Integer.parseInt(rs.getString(7));
				data.bili2 = Integer.parseInt(rs.getString(8));
				data.bili3 = Integer.parseInt(rs.getString(9));
				data.bili4 = Integer.parseInt(rs.getString(10));
				String openTime = rs.getString("timeGrade");
				if (openTime != null && !"".equals(openTime) && openTime.length() == 11) {
					String[] arrOpenTime = openTime.split(",");
					if (arrOpenTime.length == 6) {
						data.openTime.add(Integer.parseInt(arrOpenTime[0]));
						data.openTime.add(Integer.parseInt(arrOpenTime[1]));
						data.openTime.add(Integer.parseInt(arrOpenTime[2]));
						data.openTime.add(Integer.parseInt(arrOpenTime[3]));
						data.openTime.add(Integer.parseInt(arrOpenTime[4]));
						data.openTime.add(Integer.parseInt(arrOpenTime[5]));
					}
				} 
				if (data.openTime.size() != 6) {
					data.openTime.clear();
					data.openTime.add(0);
					data.openTime.add(0);
					data.openTime.add(0);
					data.openTime.add(0);
					data.openTime.add(0);
					data.openTime.add(0);
				}
				data.robotintable = rs.getInt(12);
				avatarparammanager.getInstance().Add(data);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			log.warn("Sql:" + sql + "错误");
		}
	}
	public static void updateparam(String name, String val)
	{
		String sql = "select * from avatarparam";
		CachedRowSet rs = SqlHelper.getResultSet(sql);
		try {
			while (rs.next()) 
			{  
				avatarparamdata data = new avatarparamdata();
				data.id  = Integer.parseInt(rs.getString(1));
				data.difen  = Integer.parseInt(rs.getString(2));
				data.type  = Integer.parseInt(rs.getString(3));
				data.chaoguorennum  = Integer.parseInt(rs.getString(4));
				data.chaoguojiqirennum  = Integer.parseInt(rs.getString(5));
				data.robotcount  = Integer.parseInt(rs.getString(6));
				data.bili1 = Integer.parseInt(rs.getString(7));
				data.bili2 = Integer.parseInt(rs.getString(8));
				data.bili3 = Integer.parseInt(rs.getString(9));
				data.bili4 = Integer.parseInt(rs.getString(10));
				String openTime = rs.getString("timeGrade");
				if (openTime != null && !"".equals(openTime) && openTime.length() == 11) {
					String[] arrOpenTime = openTime.split(",");
					if (arrOpenTime.length == 6) {
						data.openTime.add(Integer.parseInt(arrOpenTime[0]));
						data.openTime.add(Integer.parseInt(arrOpenTime[1]));
						data.openTime.add(Integer.parseInt(arrOpenTime[2]));
						data.openTime.add(Integer.parseInt(arrOpenTime[3]));
						data.openTime.add(Integer.parseInt(arrOpenTime[4]));
						data.openTime.add(Integer.parseInt(arrOpenTime[5]));
					}
				} 
				if (data.openTime.size() != 6) {
					data.openTime.clear();
					data.openTime.add(0);
					data.openTime.add(0);
					data.openTime.add(0);
					data.openTime.add(0);
					data.openTime.add(0);
					data.openTime.add(0);
				}
				data.robotintable = rs.getInt(12);
				avatarparammanager.getInstance().Set(data);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			log.warn("Sql:" + sql + "错误");
		}
	}
}
